﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace HubbleTelescope.Model
{
    /// <summary>
    /// Class exposing operations to the Hubble space telescope
    /// </summary>
    public class Telescope
    {
        /// <summary>
        /// Event when MeasurePlanets method has data available
        /// </summary>
        public event EventHandler<PlanetEventArgs> PlanetsMeasured = delegate { };

        /// <summary>
        /// Asynchronously sends message to the hubble space telescope for the current diameter of the planets.
        /// OK, not really, just sleeps for 3 sec and fires the PlanetsMeasured event
        /// </summary>
        public void MeasurePlanets()
        {
            ThreadPool.QueueUserWorkItem(_ =>
            {
                Thread.Sleep(3000);

                PlanetsMeasured(this, new PlanetEventArgs(new Planet[]
                    {
                        new Planet { Name = "Mercury", Diameter = 4880 },
                        new Planet { Name = "Venus", Diameter = 12104 },
                        new Planet { Name = "Earth", Diameter = 12756 },
                        new Planet { Name = "Mars", Diameter = 6794 },
                        new Planet { Name = "Jupiter", Diameter = 142984 },
                        new Planet { Name = "Saturn", Diameter = 120536 },
                        new Planet { Name = "Uranus", Diameter = 51118 },
                        new Planet { Name = "Neptune", Diameter = 49532 },

                        //Wait! this isn't a planet
                        //new Planet { Name = "Pluto", Diameter = 2274 },
                    }));
            });
        }
    }
}
